﻿#ifndef COMCLIENTMANAGE_H
#define COMCLIENTMANAGE_H

#include <QObject>
#include <QThread>
#include "ComBase.h"
#include "ComClientStatusWidget.h"
#include "WidgetComClient.h"

class ComClientManage : public QObject
{
    Q_OBJECT
public:
    explicit ComClientManage(QObject *parent = nullptr);
    QWidget* getComClientStatusWidget(){return wgtComClientStatus;}
    QWidget* getComClientManageWidget(){return mComClientManageWidget;}
    QMap<QString, ComBase*> getComClientAll(){return mMapComClient;}
    //
    void setConfigWriteOneFunc(void (*func)(const ComClientConfig& config));
    void setConfigReadAllFunc(QMap<QString, ComClientConfig> (*func)());
    void setConfigReadOneFunc(ComClientConfig (*func)(QString camName));
    void startWorker();
    void checkComClientStatus();
    void initComClientAll();
    void initWgtComClientStatus();
    void initComClientManageWidget();

public slots:
    void onAddOne(const ComClientConfig& config);
    void onDeleteOne(const QString& name);
    void onConfigChanged(const ComClientConfig& config);
signals:
    void sigComClientStatus(bool isOnLine);

private:
    void initComClientOne(ComClientConfig config);

private:
    //函数指针，用于配置读写配置的函数
    void (*configWriteOne)(const ComClientConfig& config);
    QMap<QString, ComClientConfig> (*configReadAll)();
    ComClientConfig (*configReadOne)(QString comName);

private:
    QMap<QString, ComBase*> mMapComClient;
    QMap<QString, QThread*> mMapComThread;
    QMap<QString, bool> mMapComStart;
    ComClientStatusWidget* wgtComClientStatus;
    WidgetComClient* mComClientManageWidget;
};

#endif // COMCLIENTMANAGE_H
